<template>
    <div class="listDiv mt10">
        <div class="searchDiv">
            <el-select v-model="obj.req.state" placeholder="全部状态" class="search_select" clearable>
                <el-option v-for="(item,index) in globalData.stateTypeAry" :key="index" :label="item.text" :value="item.value" />
            </el-select>
            <DatePicker v-model:value="obj.req.day" ph="预约时间" style="margin: 0 5px;" />
            <el-input clearable placeholder="匹配班车名称" v-model="obj.req.key" class="search_key" />
            <span class="btn search" @click="init">搜索</span>
            <span class="btn refresh" @click="obj.req.currentpage=1;init()"></span>
            <!-- <span class="btn download" @click="export_"></span> -->
            <div class="searchRight">
                <span class="btn add" @click="add">添加班车</span>
            </div>
        </div>
        <div class="table_box"><div class="table_" id="tb">
            <ul class="head">
                <li class="mw300">班车名称</li>
                <li class="wcen">发车时间</li>
                <li class="mw200">始发地</li>
                <li class="mw200">目的地</li>
                <li class="">联系人</li>
                <li class="wcen">联系方式</li>
                <li class="mw160 wcen">正常/停用</li>
                <li class="wcen">预约人数</li>
                <li class="mw200">操作</li>
            </ul>
            <div class="body">
                <ul v-for="x in obj.ary" :key="x">
                    <li class="mw300">
                        <el-tooltip class="box-item" effect="dark" :content="x.title" placement="top-start" :disabled="x.title.length<17">
                            <div class="lineOne pointer">{{x.title}}</div>
                        </el-tooltip>
                    </li>
                    <li class="wcen">{{x.starttime.substr(0,5)}}</li>
                    <li class="mw200">
                        <el-tooltip class="box-item" effect="dark" :content="x.startaddress" placement="top-start" :disabled="x.startaddress.length<10">
                            <div class="lineOne pointer">{{x.startaddress}}</div>
                        </el-tooltip>
                    </li>
                    <li class="mw200">
                        <el-tooltip class="box-item" effect="dark" :content="x.endaddress" placement="top-start" :disabled="x.endaddress.length<10">
                            <div class="lineOne pointer">{{x.endaddress}}</div>
                        </el-tooltip>
                    </li>
                    <li class="">{{x.man}}</li>
                    <li class="wcen">{{x.mobile}}</li>
                    <li class="mw160 wcen">
                        <el-switch v-model="x.state" size="small" :validate-event="false" @change="setstate(x)"
                            active-text="" inactive-text=""
                            active-value="1" inactive-value="0">
                        </el-switch>
                    </li>
                    <li class="base-color pointer wcen"><u @click="sign(x)">{{x.signCou}}</u></li>
                    <li class="mw200">
                        <el-button class="edit_btn mr10" type="success" @click="edit(x)">修改</el-button>
                        <DelConfirm class="" @yesClick="del(x)" />
                    </li>
                </ul>
            </div>
        </div>
        </div><Pager :value="obj.req" :init="init" />

        <el-dialog v-model="obj.drawer.design" :title="obj.drawer.designTitle" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
            <Edit :car_id="obj.drawer.car_id" @close="obj.drawer.design = false" @init="init" />
        </el-dialog>
        <el-dialog v-model="obj.drawer.sign" :title="obj.drawer.signTitle" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
            <Sign :car_id="obj.drawer.car_id" :day="obj.req.day" @close="obj.drawer.sign = false" />
        </el-dialog>
    </div>
</template>

<script setup>
    import { reactive, getCurrentInstance, ref, toRefs, provide, computed } from 'vue'
    import DatePicker from '@/components/date_picker.vue'
    import Pager from '@/components/pager.vue'
    import DelConfirm from '@/components/del_confirm.vue'
    import Edit from "./car_edit.vue"
    import Sign from "./car_sign.vue"
    let { proxy } = getCurrentInstance()

    let obj = reactive({
        drawer: {
            car_id:"",
            design: false,
            designTitle: "",
            sign: false,
            signTitle: "",
        },
        ary: [],
        req: {
            currentpage: 1,
            pagesize: 10,
            count: 0,
            key: "",
            state:"",
            day: proxy.$utils.dateFormat(new Date(), "yyyy-MM-dd"),
        }
    });
    let init = () => {
        proxy.$ajax({
            url: '/life/car_list',
            data: obj.req,
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                obj.ary = d.msg.list
                obj.req.count = d.msg.count
            }
        }).catch(() => { })
    }

    let add = () => {
        obj.drawer.design = true
        obj.drawer.designTitle = "添加班车"
        obj.drawer.car_id = "0";
    }
    let edit = x => {
        obj.drawer.design = true
        obj.drawer.designTitle = "修改班车"
        obj.drawer.car_id = x.car_id;
    }

    let sign = x => {
        obj.drawer.sign = true
        obj.drawer.signTitle = `${x.title} 预约列表`
        obj.drawer.car_id = x.car_id;
    }

    let setstate = x => {
        proxy.$ajax({
            url: '/life/car_setstate',
            data: { car_id: x.car_id},
            bfLoading: true
        }).then(d => {
            if(d.success){
                proxy.elMessageMixin("状态变更成功", 'success')
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
    let del = x => {
        proxy.$ajax({
            url: '/life/car_delete',
            data: { car_id: x.car_id },
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                proxy.elMessageMixin("删除成功", "success")
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
</script>

<style scoped>
    ::-webkit-scrollbar { width:10px; background-color: #FFFFFF; }
    .search_select { width:100px!important; }
    .search_key { width:160px!important; }
    #tb ul li.li0 { width: 160px; }
    #tb ul li.li1 { width: 100px; }
    #tb ul li.li2 { width: 60px; }
    #tb ul li.li3 { width: 85px; }
    #tb ul li.li4 { width: 65px; }
    #tb ul li.li4 u { cursor: pointer; }
</style>